#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QLineEdit>
#include <QRadioButton>
#include <QPushButton>
#include <QLabel>
#include <QHostAddress>

namespace Ui {
class Widget;
}

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = nullptr);
    ~Widget();

    // these names can be confusing, they are used to set widgets' properties
    void setServerAddress(const QString& address) { inputAddress->setText(address); }
    void setServerPort(const QString& port) { inputPort->setText(port); }
    void enableServerMode(bool value) { btnEnableServer->setChecked(value); }

    void startConnection();
    void enableWidgets(bool value);

signals:
    void launchServer(quint16 port);
    void launchClient(const QHostAddress& serverAddress, quint16 serverPort);

private:
    void initUi();
    void initConnections();

    Ui::Widget *ui;

    QLineEdit *inputAddress, *inputPort;
    QLabel *labelAddress, *labelPort;
    QRadioButton *btnEnableServer;
    QPushButton *btnConnect;
};

#endif // WIDGET_H
